﻿import request from "@/utils/request";
import { useSettingsStore } from "@/store";
import { detectRecord, detectRecordDetail, detectRecordProcessData } from "@/types/business/record";
import { pageParam, pageRecordFilter, pageResult } from "@/types/business/pageParam";

const settingStore = useSettingsStore();
const BASE_URL = `/api/${settingStore.elementRoutePrefix}/record`;

const RecordAPI = {
  /**
   * 获取检测记录分页
   * @param param
   */
  getPage(param: pageParam<pageRecordFilter>) {
    return request<any, pageResult<detectRecord>>({
      url: `${BASE_URL}/GetPage/`,
      method: "post",
      data: param,
      headers: {
        "Content-Type": "application/json",
      },
    });
  },

  /**
   * 获取检测记录详情
   * @param id 检测记录Id
   */
  getDetail(id: number) {
    return request<any, detectRecordDetail[]>({
      url: `${BASE_URL}/GetRecordDetail/${id}`,
      method: "post",
    });
  },

  /**
   * 获取检测记录详情
   * @param id 检测记录Id
   * @param recordTime 检测记录创建时间
   */
  getProcessData(id: number, recordTime: Date) {
    const formData = new FormData();
    formData.append("recordId", id.toString());
    formData.append("recordCreateTime", useDateFormat(recordTime, "YYYY-MM-DD").value);
    return request<any, detectRecordProcessData[]>({
      url: `${BASE_URL}/GetProcessData/`,
      method: "post",
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },

  /**
   * 上传检测记录
   * @param id
   */
  upload(id: number) {
    return request<any, any>({
      url: `${BASE_URL}/Upload/${id}`,
      method: "post",
    });
  },

  /**
   * 删除检测记录
   * @param id
   */
  delete(id: number) {
    return request<any, any>({
      url: `${BASE_URL}/Delete/${id}`,
      method: "post",
    });
  },
};

export default RecordAPI;
